﻿using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;

namespace PIMS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DataController
    {
        [HttpGet]
        public int  Get()
        {
            //TODO
            //FormMain.FreshData();
            return 123;
        }

        public ApiResult Post([FromBody] ApiResult mod)
        {
            try
            {
                //new PalletService().SavePallet(mod);
                return new ApiResult(true);

            }
            catch (System.Exception ex)
            {
                return new ApiResult(ex);
            }
        }

    }
    public class ApiResult
    {
        public ApiResult()
        {
            IsSuccess = true;
            code = 200;
            //statusCode = 200;
        }
        public ApiResult(bool result)
        {
            if (result)
            {
                IsSuccess = true;
                code = 200;
                msg = "OK";
            }
            else
            {
                IsSuccess = false;
                code = 199;
                msg = "ERROR";
            }
            //statusCode = 200;
        }
        public ApiResult(Exception ex)
        {
            IsSuccess = false;
            code = -1;
            msg = ex.Message;
        }
        public bool IsSuccess { get; set; }
        public int code { get; set; }
        //public int statusCode { get; set; }
        public object datas { get; set; }
        //public object datelist { get; set; }
        //public object selectlist { get; set; }
        public string msg { get; set; }
    }
}
